<template>
    <div>
        <el-dialog title="详情" v-model="isShowDialog" width="600px" @close="closeDialog">
            <el-form :model="formModel" :disabled="true" size="default" label-width="120px">
                <el-form-item label="脚本名称" prop="scriptName">
                    <el-input v-model="formModel.scriptName" show-word-limit maxlength="20" placeholder=""
                        clearable></el-input>
                </el-form-item>
                <el-form-item label="脚本" prop="script">
                    <el-input v-model="formModel.script" :rows="5" type="textarea" show-word-limit placeholder=""
                        clearable></el-input>
                </el-form-item>
                <el-form-item label="备注" prop="remark">
                    <el-input v-model="formModel.remark" show-word-limit maxlength="500" placeholder=""
                        clearable></el-input>
                </el-form-item>
            </el-form>
            <template #footer>
                <span class="dialog-footer">
                    <el-button @click="() => closeDialog()" size="default">关 闭</el-button>
                </span>
            </template>
        </el-dialog>
    </div>
</template>

<script lang="ts">
import { reactive, toRefs, defineComponent, inject } from 'vue';
import { TaskScriptDetailModel } from '/@/interfaces/DataPipelineModel';
import useObjectUtil from '/@/utils/objectUtil';

interface State {
    isShowDialog: boolean | true,
    submitLoading: boolean | false,
    formModel: TaskScriptDetailModel,
    selectDictType: {},
}
export default defineComponent({
    name: 'TaskScriptDetail',
    components: {},
    emits: ['onClose'],
    setup(props, context) {
        const state = reactive<State>({
            isShowDialog: true,
            submitLoading: false,
            formModel: {
                id: undefined,
                scriptName: undefined,
                script: undefined,
                remark: undefined,
            },
            selectDictType: {},
        });
        const methodMap = reactive({
            // 关闭弹窗
            closeDialog: function () {
                state.isShowDialog = false;
                context.emit('onClose');
            }
        });
        // 表单赋值
        const detailData: TaskScriptDetailModel | undefined = inject<TaskScriptDetailModel>('detailData');
        if (undefined !== detailData) {
            useObjectUtil.copyProperties(detailData, state.formModel);
        } else {
            console.error("found undefined for detail");
        }
        return {
            ...toRefs(state),
            ...toRefs(methodMap),
        };
    },
});
</script>
